﻿using System;
using Bingosoft.Core;
using Bingosoft.Modules.SecurityConsole.Privilege;
using Bingosoft.Web.Utils;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Privilege
{
    public partial class FunctionEdit : System.Web.UI.BasePage
    {
        private PrivilegeService _privilegeService;

        private PrivilegeService PrivilegeService
        {
            get
            {
                return _privilegeService ??
                       (_privilegeService =
                        App.Current.GetObjectContainer().GetObject("PrivilegeService") as PrivilegeService);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化页面元素
            if (!this.IsPostBack && this.SmartFormView1.IsInsert())
            {
                this.SmartFormView1["Parent"] = Request.Params["ParentId"];
            }
        }

        protected void SaveFunction(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.SmartFormView1["Id"] as string) &&
                this.PrivilegeService.CheckUniqueOperation(this.SmartFormView1["Code"] as string))
            {
                ScriptHelper.Alert(this, "您输入的功能代码已经存在，请换一个功能编码试试");
            }
            else
            {
                this.SmartFormView1.SaveOrUpdate();
                ScriptHelper.CloseDialog(this, "true");
            }
        }
    }
}